package com.holyant.report.dto;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

/**
 * @author zgx *
 * @date 2022年08月05日 13:51
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RptBrandInventorySummaryInfoDto {

    @ApiModelProperty(name = "销量")
    private BigDecimal salesQtys;

    @ApiModelProperty(name = "期初库存/罐")
    private BigDecimal beginningInventoryQtys;

    @ApiModelProperty(name = "采购入库/罐")
    private BigDecimal procurementWarehousingQtys;

    @ApiModelProperty(name = "期末库存/罐")
    private BigDecimal endInventoryQtys;

    @ApiModelProperty(name = "采购在途")
    private BigDecimal procurementInTransitQtys;

    @ApiModelProperty(name = "调拨在途")
    private BigDecimal transfersInTransitQtys;

    @ApiModelProperty(name = "到货破损/罐")
    private BigDecimal toCargoBrokenQtys;

    @ApiModelProperty(name = "退货/罐")
    private BigDecimal salesReturnQtys;

    @ApiModelProperty(name = "FM国内库存/罐")
    private BigDecimal fmInternals;

    @ApiModelProperty(name = "FM香港库存")
    private BigDecimal fmOverseass;


    public static RptBrandInventorySummaryInfoDto summaryRptBrandInventoryInfoDto(List<RptBrandInventoryInfoDto> rptBrandInventoryInfoDto){
        if (CollectionUtils.isEmpty(rptBrandInventoryInfoDto))return new RptBrandInventorySummaryInfoDto();
        return RptBrandInventorySummaryInfoDto.builder()
                .salesQtys(rptBrandInventoryInfoDto.stream().filter(item-> Objects.nonNull(item.getSalesQty())).map(RptBrandInventoryInfoDto::getSalesQty).reduce(BigDecimal::add).get())
                .beginningInventoryQtys(rptBrandInventoryInfoDto.stream().map(RptBrandInventoryInfoDto::getBeginningInventoryQty).reduce(BigDecimal::add).get())
                .procurementWarehousingQtys(rptBrandInventoryInfoDto.stream().map(RptBrandInventoryInfoDto::getProcurementWarehousingQty).reduce(BigDecimal::add).get())
                .endInventoryQtys(rptBrandInventoryInfoDto.stream().map(RptBrandInventoryInfoDto::getEndInventoryQty).reduce(BigDecimal::add).get())
                .procurementInTransitQtys(rptBrandInventoryInfoDto.stream().map(RptBrandInventoryInfoDto::getProcurementInTransitQty).reduce(BigDecimal::add).get())
                .transfersInTransitQtys(rptBrandInventoryInfoDto.stream().map(RptBrandInventoryInfoDto::getTransfersInTransitQty).reduce(BigDecimal::add).get())
                .toCargoBrokenQtys(rptBrandInventoryInfoDto.stream().map(RptBrandInventoryInfoDto::getToCargoBrokenQty).reduce(BigDecimal::add).get())
                .salesReturnQtys(rptBrandInventoryInfoDto.stream().map(RptBrandInventoryInfoDto::getSalesReturnQty).reduce(BigDecimal::add).get())
                .fmInternals(rptBrandInventoryInfoDto.stream().map(RptBrandInventoryInfoDto::getFmInternal).reduce(BigDecimal::add).get())
                .fmOverseass(rptBrandInventoryInfoDto.stream().map(RptBrandInventoryInfoDto::getFmOverseas).reduce(BigDecimal::add).get())
                .build();
    }

}
